"use strict";(function(){this.pixelExtensions=["volume_discounts","product_bundles","sales_notification","buyx_gety"],this.isAdmin=function(){return document.querySelector("#admin-bar-iframe")||window.Shopify.designMode},this.init=function(){this.cart=null,this.refCartItems=null,this.shopRootUrl=window.Shopify.routes.root,this.updateCartCallbacks=[],this.addCartCallbacks=[],this.pixelInit(),this.registerEvents(),this.selectorsInit()},this.pixelInit=function(){window.Shopify&&!this.isAdmin()&&(document.addEventListener("ER_PIXEL_PAGE_VIEWED",t=>{let e=t.detail;if(e.extension&&this.pixelExtensions.includes(e.extension)){let s={extension:e.extension,productId:e.data.productId||"",rule_id:e.data?.configs?.id};"sales_notification"===e.extension&&this.shop&&this.shop.permissions&&(s.sale_notification_limit=this.shop.permissions.sale_notification_limit||0),this.sendPixel("er_page_viewed",s)}}),document.addEventListener("ER_PIXEL_PRODUCT_VIEWED",t=>{let e=t.detail;if(e.extension&&this.pixelExtensions.includes(e.extension)){let s={extension:e.extension,productId:e.data.productId||"",rule_id:e.data?.configs?.id};this.sendPixel("er_product_viewed",s)}}),document.addEventListener("ER_PIXEL_EVENT",t=>{let e=t.detail;if(e.extension&&this.pixelExtensions.includes(e.extension)){let s={extension:e.extension,productId:e.data.productId||"",event:e.data?.event};this.sendPixel("er_events",s)}}),document.addEventListener("ER_PIXEL_CART_ADDED",t=>{let e=t.detail;if(e.extension&&this.pixelExtensions.includes(e.extension)){let s={extension:e.extension,productId:e.productId||"",rule_id:e?.configs?.id,quantity:e.quantity};this.sendPixel("er_add_to_cart",s)}}),document.addEventListener("ER_PIXEL_CHECKOUT_START",t=>{let e=t.detail;if(e.extension&&this.pixelExtensions.includes(e.extension)){let s=e.data,i={extension:e.extension,data:{checkout:{token:s.token,currencyCode:s.currency,lineItems:s.items.map(t=>({id:t.product_id+"",title:t.product_title+"",quantity:t.quantity,variant:{id:t.variant_id+"",price:{amount:t.price,currencyCode:s.currency},product:{id:t.product_id+"",title:t.product_title+""},sku:t.sku}}))}}};this.sendPixel("er_checkout_start",i)}}))},this.sendPixel=function(t,e){if(window.Shopify.analytics)Shopify.analytics.publish(t,e);else{var s=0;let i=setInterval(function(){window.Shopify.analytics&&(Shopify.analytics.publish(t,e),clearInterval(i)),++s>200&&clearInterval(i)},100)}},this.registerEvents=function(){var t,e;let s=document.querySelectorAll("form[action*='/cart/add']:not(.installment)");for(let i of s){let r=i.getAttribute("id"),a=i.querySelector('[name="id"]')||document.querySelector(`input[name="id"][form="${r}"]`);a&&a.addEventListener("change",t=>{let e=Number(t.target.value);i.dispatchEvent(new CustomEvent("ER_VARIANT_CHANGE",{detail:e}))})}t=window,"function"==typeof(e=window.fetch)&&(t.fetch=function(){let t=e.apply(this,arguments);return t.then(t=>{let e=`${window.location.origin}${window.EComRise.settings.baseUrl}`;[`${e}cart/add`,`${e}cart/add.js`].includes(t?.url)&&200===t.status&&t.clone().json().then(t=>{window.document.dispatchEvent(new CustomEvent("ER_CART_ITEM_ADD",{detail:t}))}),[`${e}cart/change`,`${e}cart/change.js`,`${e}cart/update.js`,`${e}cart/update`,`${e}cart/clear`,`${e}cart/clear.js`,].includes(t.url)&&200===t.status&&t.clone().json().then(t=>{window.document.dispatchEvent(new CustomEvent("ER_CART_UPDATE",{detail:t}))})}),t}),document.addEventListener("ER_CART_UPDATE",t=>{this.updateCartCallbacks.forEach(e=>{e(t.detail)})}),document.addEventListener("ER_CART_ITEM_ADD",t=>{this.addCartCallbacks.forEach(t=>{t()})})},this.selectorsInit=()=>{this.selectors||(this.selectors={formProduct:'product-form form, form.product-form, form.main-product-form, form.product-single__form, form[action*="/cart/add"]',formCart:'form[action$="/cart"] form#cart, form#CartDrawer',cartDrawer:"cart-drawer, drawer-cart",cartCount:".cart-count-bubble > span:first-child, .sf-cart-count, [data-cart-count-number],[data-cart-count], .header__cart-count .count-bubble",subtotalValue:[".totals__subtotal-value, [data-cart-subtotal-price], .sf-cart-subtotal__price, [data-cart-price], #CartDrawer [data-subtotal], .cart__page [data-subtotal]",],cartSummary:[".cart__footer > .cart__blocks > .js-contents, .sf-cart__summary .scd__summary, .scd__footer .scd__summary, .cart-drawer__footer, .m-cart__summary, #CartDrawer [data-discounts], .cart__page [data-discounts], .t4s-cart-total, .hdt-cart-totals-discounts, .cart__footer .cart__blocks, .bls-cart-footer .bls-cart-discounts, .ecom-cart__informations-container",],checkoutButton:['button[id="checkout"], button[name="checkout"], input[id="checkout"], input[name="checkout"], .hdt-mini-cart__btn-checkout, .t4s-btn__checkout',]})},this.getCart=async()=>(this.cart||(this.cart=await this.Utils.fetchDataJson(EComRise.shopRootUrl+"cart.json")),this.cart),this.getDomEls=()=>Object.entries(this.selectors).reduce((t,[e,s])=>{let i="string"==typeof s,r=i?s:s[0];return t[e]=document?.[i?"querySelector":"querySelectorAll"]?.(r),!i&&t[e]&&(t[e]=[...t[e]]),t},{}),this.clearCartTotalDomEls=t=>{let e=this.getDomEls();e.cartSummary?.length&&e.cartSummary.forEach(e=>{for(let s of e.querySelectorAll(t))s.remove()})},this.updateCart=async()=>{document.addEventListener("ER_CART_UPDATE",t=>{this.updateCartCallbacks.forEach(e=>{e(t)})}),document.addEventListener("ER_CART_ITEM_ADD",t=>{this.addCartCallbacks.forEach(t=>{t()})})},this.onAddedToCart=(t,e,s="")=>{switch(e){case"PAGE_CART":window.location.href=this.settings.baseUrl+"cart";break;case"CHECKOUT":window.location.href=this.settings.baseUrl+"checkout";break;case"PAGE_CURRENT":setTimeout(()=>{window.location.reload()},1500);break;case"THEME_CART":(function e(){switch(s){case"dawn":let i=document.querySelector("cart-notification")||document.querySelector("cart-drawer");i&&(i.renderContents(t),i.classList.remove("is-empty"));break;case"kalles":case"usen":case"gecko":document.dispatchEvent(new CustomEvent("cart:refresh:opend"));break;case"ecomus":document.getElementById("CartDrawer")?.openDialog(),document.documentElement.dispatchEvent(new CustomEvent("cart:refresh",{bubbles:!0}));break;case"origin":case"sense":let r=document.querySelector("cart-notification")||document.querySelector("cart-drawer"),a=document.querySelector("cart-drawer-items");document.querySelector("cart-drawer")&&document.querySelector("cart-drawer").classList.remove("is-empty"),fetch(`${routes.cart_url}?section_id=main-cart-items`).then(t=>t.text()).then(e=>{let s=new DOMParser().parseFromString(e,"text/html"),i=s.querySelector("cart-items");a.innerHTML=i.innerHTML,r.renderContents(t)}).catch(t=>{console.error(t)});break;case"debutify":window.ajaxCart&&"function"==typeof window.ajaxCart&&ajaxCart.load();break;case"prestige":document.dispatchEvent(new CustomEvent("product:added",{bubbles:!0,detail:{variant:t.items[0].variant_id,quantity:1}}))}})()}},this.Utils={bindEvent(t,e,s){t.split(" ").forEach(t=>{document.addEventListener(t,function(t){t.target.matches(e+", "+e+" *")&&s.apply(t.target.closest(e),arguments)},!1)})},addEvent({context:t=document.documentElement,type:e="click",selector:s,handler:i,capture:r=!1}){let a=function(t){for(let e=t.target;e&&e!==this;e=e.parentNode)if(e.matches(s)){i.call(e,t,e);break}};return t.addEventListener(e,a,r),()=>{t.removeEventListener(e,a,r)}},checkRequiredInput:function(t){if(!t)return;let e=t.querySelectorAll('[data-theme-fields] [name][required]:not([hidden]):not([type="hidden"])'),s=[];return e.forEach(t=>{if("radio"===t.type){let e=t.querySelectorAll(`input[name="${n.name}"]`);Array.from(e).some(t=>t.checked)||s.push(t)}else t.value||s.push(t)}),s},createDomEl(t="div",e="",s=""){let i=document.createElement(t),r=e.split(" ");return r.forEach(t=>{i.classList.add(t)}),i.innerHTML=s,i},getSessionStore(t){let e=sessionStorage.getItem(t);return e?!function(t){try{JSON.parse(t)}catch(e){return!1}return!0}(e)?e:JSON.parse(e):null},setSessionStorage(t,e){sessionStorage.setItem(t,"string"!=typeof e?JSON.stringify(e):e)},deleteSessionStorage(t){sessionStorage.removeItem(t)},fetchDataJson:t=>new Promise((e,s)=>{fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}}).then(t=>{if(t.ok){let i=t.json();return e(i)}s(t)}).catch(s)}),calculateStorePrice(t,e=!0,s=!0){if(isNaN(t))return t;let i=parseFloat(window?.Shopify?.currency?.rate);(isNaN(i)||i<=0)&&(i=1);let r=e?t/i:t*i;return s?parseFloat(r.toFixed(2)):r},typoStyle:t=>`font-size: ${t?.font_size||"18px"};color: ${t?.color||"#000"};font-weight: ${t?.font_weight||"500"};font-style: ${t?.font_style||"normal"};line-height: ${t?.line_height||"unset"};text-transform: ${t?.text_transform||"unset"};letter-spacing: ${t?.letter_spacing||"unset"};text-decoration: ${t?.text_decoration||"unset"};`},this.init()}).bind(window.EComRise||{})(),function(t){t.data.volume_discount&&(t.VolumeDiscounts=new class{constructor(){this.initCart(),this.updateCart(),this.locale=t.data.volume_discount.hasOwnProperty("locale")?t.data.volume_discount.locale:{}}async initCart(e=null){t.clearCartTotalDomEls(".er-cart-volume-discount");let s=e;null!==s||(s=await t.getCart(),t.refCartItems||(t.refCartItems=s.items)),t.cart=s;let i=[],{ErCart:r}=await (async e=>{if(!e||!e?.items?.length)return{ErCart:e};delete e?.sections;let s={...e},r=s?.items,a=[],c=[],o=0,l=[],u=t.Utils.getSessionStore("ER_CartItems")||[];return r.forEach((e,d)=>{c.push((async()=>{let c=Array.isArray(u)?u.findIndex(t=>t.key===e.key):-1,h,p,m;if(-1!==c){let f=u[c];p=f.ER_discount_item,h=this.nearestObject(p.rules,e.quantity)}else{let g=await this.getCollectionIdsFromHandle(e.handle);p=await this.getConfigs({productId:e.product_id,collectionIds:g})}let _=p?.id||p?.volume_id;if(p?.rules.length){let $=r.reduce(function(t,s){return s.product_id===e.product_id&&(t+=s.quantity),t},0);if(h=this.nearestObject(p.rules,$)){let E=t.refCartItems.find(t=>t.id==e.id),y=E?E.price:e.price,C=this.calculateDiscount(y,h,!1)*e.quantity;o+=C;let b=t.data.volume_discount.hasOwnProperty("locale")?t.data.volume_discount.locale:{},v="PERCENTAGE"===h.type?`${h.value}%`:window.EComRise.formatMoney(100*window.EComRise.Utils.calculateStorePrice(parseFloat(h.value),!1)),D="FIXED_PRICE"===h.type?(b?.text_rule_price_fixed||"Get each product for {value}").replace(/{\s*value\s*}/g,v):b.text_rule.replace(/{\s*quantity\s*}/g,h.quantity).replace(/{\s*value\s*}/g,v);m=p.title||"Volume discount",s.items[d].ER_discount_item={ruleApply:{...h,title:m,label:D},volume_id:_,rules:p.rules,price:y,line_price:e.line_price,discount_amount:this.calculateDiscount(y,h),title:m,label:D},s.items[d].erPrices||(s.items[d].erPrices={price:y}),i.push({...s.items[d]}),a.push({volume_id:_,product_id:e.product_id,label:D,rule:h});let R=l.findIndex(t=>t.id==_);R<0?l.push({id:_,title:m,discount_amount:C}):l[R].discount_amount+=C}}})())}),await Promise.all(c),a.length&&(s.attributes.ER_VolumeDiscount=a,s.ER_Price={items_subtotal_price:s.items_subtotal_price-o,original_total_price:s.original_total_price-o,discount_amount:o},s.ER_VolumeDiscount=l),{ErCart:s}})(s||{});this.cart=r,t.Utils.setSessionStorage("ER_CartItems",i),this.renderCartDiscount(),document.dispatchEvent(new CustomEvent("ER_CART_INIT",{detail:r}))}updateCart(){t.updateCartCallbacks.push(t=>{this.initCart(t)}),t.addCartCallbacks.push(t=>{this.initCart()})}renderCartDiscount(){let e=t.getDomEls();if(e.cartSummary?.length)e.cartSummary.forEach(t=>{this.cart?.ER_Price?.discount_amount&&this.cart?.ER_VolumeDiscount&&this.cart?.ER_VolumeDiscount.forEach(e=>{t.prepend(this.cartDiscountHTML(e))})});else{let s=0;new Promise(e=>{let i=setInterval(()=>{let r=document.querySelectorAll(t.selectors.cartSummary);(r.length||s>=40)&&(e(r),clearInterval(i)),s++},250)}).then(t=>{t.length&&t.forEach(t=>{this.cart?.ER_Price?.discount_amount&&this.cart?.ER_VolumeDiscount&&this.cart?.ER_VolumeDiscount.forEach(e=>{t.prepend(this.cartDiscountHTML(e))})})})}this.renderCartItem()}renderCartItem(){this.cart.items.length&&(this.cart.items.forEach(e=>{if(!e?.ER_discount_item)return;let s=document.querySelector(`[data-key="${e.key}"]`);if(s){let i=e.ER_discount_item.ruleApply,r=this.calculateDiscount(e.price,i,!1),a=e.price-r;s.querySelector("[data-er-cart-item-price]")&&(s.querySelector("[data-er-cart-item-price]").innerHTML=`${t.formatMoney(e.price)}${t.formatMoney(a)}`),s.querySelector("[data-er-cart-item-line-price]")&&(s.querySelector("[data-er-cart-item-line-price]").innerHTML=`${t.formatMoney(e.original_line_price)}${t.formatMoney(a*e.quantity)}`)}}),this.cart.ER_Price&&document.querySelector("[data-er-cart-total-price]")&&(document.querySelector("[data-er-cart-total-price]").innerHTML=`${t.formatMoney(this.cart.total_price)}${t.formatMoney(this.cart.total_price-this.cart.ER_Price.discount_amount)}`))}cartDiscountHTML(e){if(!e?.title||!e?.discount_amount)return"";let s=` ${e.title} (- ${t.formatMoney(e.discount_amount)})`;return t.Utils.createDomEl("div","er-cart-discount er-cart-volume-discount",s)}calculateDiscount(e,s,i=!0){let r=0;return r="PERCENTAGE"===s.type?e*Number(s.value)/100:t.Utils.calculateStorePrice(parseFloat(100*s.value),!1),i?parseFloat(r).toFixed(2):parseFloat(r)}async getCollectionIdsFromHandle(e){try{let s=t.Utils.getSessionStore(`er_volume_discount_${e}`);if(s&&Array.isArray(s)&&s.length>0)return s;let i=await this.fetchDataHTML(`${t.settings.baseUrl}products/${e}?section_id=ecomrise-product-json`,"[er-data-collections-json]");return s=(i||[]).map(t=>t.id),t.Utils.setSessionStorage(`er_volume_discount_${e}`,s),s}catch(r){console.log(r)}}async getConfigs(e={},s=!0){let{productId:i,collectionIds:r,productTags:a,productPrice:c}=e,o=[];if(i&&t.data.volume_discount.data.length){let l=t.data.volume_discount.data,u=null,d=l.some(t=>t.countries&&t.countries.length);if(d){let h=await t.Utils.fetchDataJson("https://api.country.is");h&&(u=h.country)}o=l.filter(e=>{if("deactive"===e.status||"shopify_function"===e.discount_method&&s)return!1;let c=!1,o=new Date;if((e?.active_date&&new Date(e.active_date)>o||e?.end_date&&new Date(e.end_date)=0){d=!0;break}}else{d=!0;for(let m=0;m=0){d=!1;break}}}else d=!0;break;default:d=!0}if(!d)return!1}if(e.countries&&e.countries.length&&(!u||!e.countries.includes(u)))return!1;if(e.hasAnyTag&&e.hasAnyTag.length){if(0===a.length)return!1;let f=a.split(",");return e.hasAnyTag.some(t=>f.includes(t))}return"all"!==e.apply_type&&e.apply_to&&e.apply_to.length?e.apply_to.some(t=>t.id===i||r.includes(t.id)):"all"===e.apply_type})}return!o.length&&Shopify.designMode&&(o=e),o.length?this.filterRules(o,c):null}filterRules(t,e){return t.reduce((t,s)=>this.calculateDiscount(parseFloat(e),s.rules[0],!1)>this.calculateDiscount(parseFloat(e),t.rules[0],!1)?s:t,t[0])}async fetchDataHTML(t,e){return fetch(t,{method:"GET",headers:{"Content-Type":"text/html"}}).then(t=>t.text()).then(t=>{let s=document.createElement("div");s.innerHTML=t;let i=s.querySelector(e);if(i)return"string"==typeof i?.innerHTML?JSON.parse(i.innerHTML):i?.innerHTML}).catch(t=>console.log(t))}nearestObject(t,e){let s=t.reduce((t,s)=>s.quantity<=e&&Math.abs(s.quantity-e)e)&&s}}),t.data.buyx_gety&&(t.BuyxGety=new class{constructor(){this.locale=t.data.buyx_gety.hasOwnProperty("locale")?t.data.buyx_gety.locale:{}}async getCollectionIdsFromHandle(e){try{let s=t.Utils.getSessionStore(`er_volume_discount_${e}`);if(s&&Array.isArray(s)&&s.length>0)return s;let i=await this.fetchDataHTML(`${t.settings.baseUrl}products/${e}?section_id=ecomrise-product-json`,"[er-data-collections-json]");return s=(i||[]).map(t=>t.id),t.Utils.setSessionStorage(`er_volume_discount_${e}`,s),s}catch(r){console.log(r)}}async getConfigs(e={}){let{productId:s,collectionIds:i,productPrice:r}=e,a=[];if(s&&t.data.buyx_gety.data.length){let c=t.data.buyx_gety.data,o=null,l=c.some(t=>t.countries&&t.countries.length);if(l){let u=await t.Utils.fetchDataJson("https://api.country.is");u&&(o=u.country)}a=c.filter(e=>{if("deactive"===e.status||!e.customer_get||!e.customer_buy)return!1;let r=!1,a=new Date;if((e?.active_date&&new Date(e.active_date)>a||e?.end_date&&new Date(e.end_date)=0){l=!0;break}}else{l=!0;for(let h=0;h=0){l=!1;break}}}else l=!1;break;default:l=!0}if(!l)return!1}return(!e.countries||!e.countries.length||!!o&&!!e.countries.includes(o))&&(e.customer_buy.resources.product.some(t=>t.id===s)&&"product"===e.customer_buy.type||e.customer_buy.resources.collection.some(t=>i.includes(t.id)&&"collection"===e.customer_buy.type))})}return!a.length&&Shopify.designMode&&(a=e),a.length?this.filterConfig(a):null}filterConfig(t){let e=function(t){let e=Number(t.customer_get.resources.product[0].variants[0].price);if(!t.customer_get||!t.customer_get.customer_get_discount)return e;let s=parseFloat(window?.Shopify?.currency?.rate);(isNaN(s)||s<=0)&&(s=1);let i=t.customer_get.customer_get_discount[0],r;switch(i){case"amount":r=e-100*Number(t.customer_get.discount_amount)*s;break;case"percentage":r=e-e*(Number(t.customer_get.discount_percent)/100);break;default:r=0}return r},s=t.filter(t=>"free"===t.customer_get.customer_get_discount[0]);return s.length?s.pop():(s=t.reduce((t,s)=>{let i=e(s),r=e(t);return it.text()).then(t=>{let s=document.createElement("div");s.innerHTML=t;let i=s.querySelector(e);if(i)return"string"==typeof i?.innerHTML?JSON.parse(i.innerHTML):i?.innerHTML}).catch(t=>console.log(t))}}),t.data.product_bundle&&(t.ProductBundles=new class{constructor(){this.shopRootUrl=window.Shopify.routes.root,this.initCart(),this.updateCart(),this.locale=t.data.product_bundle.hasOwnProperty("locale")?t.data.product_bundle.locale:{}}async initCart(e=null){t.clearCartTotalDomEls(".er-cart-bundle-discount");let s=e;null!==s||(s=await t.getCart(),t.refCartItems||(t.refCartItems=s.items)),t.cart=s;let i=await (async e=>{if(!e||!e?.items?.length)return{ErCart:e};delete e?.sections;let s={...e},i=s?.items,r=await this.getConfigs({cartItems:i});return r&&r.forEach(e=>{if(e?.discount?.status!=="active")return;let r=0,a=e?.title||"Bundle discount";i.forEach(s=>{let i=t.refCartItems.find(t=>t.id==s.id),c=i?i.price:s.price,o=-1;if(e.products.find(t=>t.id==s.product_id)){let l=this.calculateDiscountedPrice(c,e.discount,!1);r+=(c-l)*s.quantity,s.ER_BundleDiscounts=[{label:this.locale?.text_discount||"Bundle discount",discount_amount:c-l,discount_type:e.discount?.type,title:a},],o=e.discount?.type==="PERCENTAGE"?Number(e.discount?.value)/100:100*parseFloat(e.discount?.value),s.ER_BundleDiscounts[0].discount_value=o}}),r>0&&(s.ER_BundleDiscounts||(s.ER_BundleDiscounts=[]),s.ER_BundleDiscounts.push({items_subtotal_price:s.items_subtotal_price-r,original_total_price:s.original_total_price-r,discount_amount:r,bundle_id:e.id,bundle_title:a}))}),s})(s||{});this.cart=i,this.renderCartDiscount(),document.dispatchEvent(new CustomEvent("ER_CART_INIT",{detail:i}))}async updateCart(){t.updateCartCallbacks.push(t=>{this.initCart(t)}),t.addCartCallbacks.push(t=>{this.initCart()})}async getConfigs(e={}){let{productId:s,cartItems:i,bundleId:r}=e,a=null;if(!t.data.product_bundle.data.length)return a;let c=t.data.product_bundle.data;if(r)return c.find(t=>t.id===r);let o=null,l=c.some(t=>t.countries&&t.countries.length);if(l){let u=await t.Utils.fetchDataJson("https://api.country.is");u&&(o=u.country)}return(!(a=c.filter(e=>{if("deactive"===e.status)return!1;let r=!1,a=new Date;if((e?.active_date&&new Date(e.active_date)>a||e?.end_date&&new Date(e.end_date)=0){l=!0;break}}else{l=!0;for(let h=0;h=0){l=!1;break}}}else l=!1;break;default:l=!0}if(!l)return!1}if(e.countries&&e.countries.length&&(!o||!e.countries.includes(o)))return!1;if(s){if(e?.apply_to?.type==="all"){if(e.products.find(t=>t.id==Number(s)))return!0}else if(e?.apply_to?.product&&e?.apply_to?.product==s)return!0}else if(i?.length){let p=0;if(e.products.forEach(t=>{i.find(e=>e.product_id===t.id&&e.quantity>=t.quantity)&&p++}),p==e.products.length)return!0}return!1})).length&&Shopify.designMode&&(a=c),a.length)?s?a[0]:a:null}calculateDiscountedPrice(e,s,i=!0){let r=0;return r="PERCENTAGE"===s.type?e*(1-Number(s.value)/100):e-t.Utils.calculateStorePrice(parseFloat(100*s.value),!1),i?r.toFixed(2):r}renderCartDiscount(){let e=t.getDomEls(),s=[];if(e.cartSummary?.length)e.cartSummary.forEach(t=>{this.cart?.ER_BundleDiscounts?.length&&(this.editFinalPrice(),this.cart?.ER_BundleDiscounts.forEach(e=>{s.includes(e.bundle_id)||t.prepend(this.cartDiscountHTML(e)),s.push(e.bundle_id)}))});else{let i=0;new Promise(e=>{let s=setInterval(()=>{let r=document.querySelectorAll(t.selectors.cartSummary);(r.length||i>=40)&&(e(r),clearInterval(s)),i++},250)}).then(t=>{t.length&&t.forEach(t=>{this.cart?.ER_BundleDiscounts?.length&&(this.editFinalPrice(),this.cart?.ER_BundleDiscounts.forEach(e=>{s.includes(e.bundle_id)||t.prepend(this.cartDiscountHTML(e)),s.push(e.bundle_id)}))})})}}editFinalPrice(){document.querySelector("[data-er-cart-total-price]")&&(document.querySelector("[data-er-cart-total-price]").innerHTML=`${t.formatMoney(this.cart.total_price)}${t.formatMoney(this.cart.total_price-this.cart.ER_BundleDiscounts.reduce((t,e)=>t+e.discount_amount,0))}`)}cartDiscountHTML(e){if(!e?.discount_amount||!e?.bundle_title)return"";let s=` ${e?.bundle_title} (- ${t.formatMoney(e.discount_amount)})`;return t.Utils.createDomEl("div","er-cart-discount er-cart-bundle-discount",s)}})}(window.EComRise||{}),function(t){(t.installed_apps?.volume_discounts||t.installed_apps?.product_bundles)&&new class{constructor(){this.API_END_POINT="/apps/ecomrise/checkout",this.CheckoutSelectors=["input[name='checkout']","input[value='Checkout']","button[name='checkout']","[href$='checkout']","button[value='Checkout']","input[name='goto_pp']","button[name='goto_pp']","input[name='goto_gc']","button[name='goto_gc']",],this.The4Selector=["a[data-drawer-options]"],this.addEvents(),document.addEventListener("ER_CART_ADDED",()=>{setTimeout(this.addEvents.bind(this),500)})}addEvents(){this.CheckoutSelectors.forEach(e=>{t.Utils.bindEvent("click",e,e=>{e.preventDefault(),e.stopPropagation();let s=e.target,i={...t.cart};if(t.installed_apps?.volume_discounts&&t.VolumeDiscounts?.cart){let r=t.VolumeDiscounts.cart;if(i.ER_Price=r?.ER_Price||null,i.ER_Price)for(let a in i.ER_Price){let c=parseFloat(i.ER_Price[a]);isNaN(c)||(i.ER_Price[a]=t.Utils.calculateStorePrice(i.ER_Price[a]))}i.attributes.ER_VolumeDiscount=r.attributes?.ER_VolumeDiscount||null,i.attributes.ER_VolumeDiscountTitle=r.attributes?.ER_VolumeDiscountTitle||null,i.items.forEach(e=>{let s=r.items.find(t=>t.id===e.id);if(s){e.ER_discount_item=s?.ER_discount_item||null;let i=parseFloat(e.ER_discount_item?.discount_amount);e.ER_discount_item&&!isNaN(i)&&(e.ER_discount_item.discount_amount=t.Utils.calculateStorePrice(i))}})}if(t.installed_apps?.product_bundles&&t.ProductBundles?.cart){let o=t.ProductBundles.cart;i.ER_BundleDiscounts=o?.ER_BundleDiscounts||null;let l=parseFloat(i.ER_BundleDiscounts?.discount_amount);i.ER_BundleDiscounts&&!isNaN(l)&&(i.ER_BundleDiscounts.discount_amount=t.Utils.calculateStorePrice(l)),i.attributes=o?.attributes||null,i.items.forEach(e=>{let s=o.items.find(t=>t.id===e.id);if(s&&(e.ER_BundleDiscounts=s?.ER_BundleDiscounts||null,e.ER_BundleDiscounts))for(let i of e.ER_BundleDiscounts){let r=parseFloat(i.discount_amount);isNaN(r)||(i.discount_amount=t.Utils.calculateStorePrice(r))}})}let u=document.querySelector("#cart_agree")||document.querySelector('.hdt-cart-checkbox [name="agree_checkbox"]');if(u&&!u.checked){if(window.themeHDN){let d=document.querySelector("#CartDrawer-Form")||document.querySelector("#CartPage-Form");d&&d.dispatchEvent(new Event("submit"))}else window.T4SThemeSP||t.Toast.showError({text:"Please agree checkbox"});return}if(!i.ER_Price&&!i.ER_BundleDiscounts){window.location.href="/checkout";return}s.style.opacity="0.7",s.style.pointerEvents="none",fetch(this.API_END_POINT,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cart:i,shop:Shopify.shop,customer:t.Customer})}).then(t=>t.json()).then(t=>{"success"===t.status&&t.invoice_url?(document.dispatchEvent(new CustomEvent("ER_PIXEL_CHECKOUT_START",{detail:{extension:"volume_discounts",data:i}})),window.location.href=t.invoice_url):(console.error("EComRise Checkout",t.message),console.error("EComRise Checkout",t.debug),window.location.href="/checkout")}).catch(t=>console.log(t))})}),window.T4SThemeSP&&this.The4Selector.forEach(e=>{let s=document.querySelectorAll(e);s.length&&s.forEach(e=>{let s=JSON.parse(e.getAttribute("data-drawer-options")||"{}");"#t4s-mini_cart"===s.id&&e.addEventListener("click",()=>{t?.VolumeDiscounts&&t.VolumeDiscounts.renderCartDiscount.bind(t.VolumeDiscounts)})})})}}}(window.EComRise||{}),function(t){class e{static hideDelay=5e3;constructor(){this.toastNode=document.createElement("div"),this.toastNode.classList.add("er-toast"),document.body.appendChild(this.toastNode)}getTransitionDuration=t=>{let e=getComputedStyle(t).transitionDuration;return e.includes("ms")?parseFloat(e):1e3*parseFloat(e)};scheduleHiding(t){setTimeout(()=>this.hideMessageNode(t),e.hideDelay)}getCrossIcon(){let t=document.createElement("div");return t.innerHTML='',t.firstChild}getMessageNode({title:t="",text:e=""}={}){let s=document.createElement("div"),i=this.getCrossIcon();return i.addEventListener("click",()=>this.hideMessageNode(s)),s.classList.add("er-toast__message"),s.appendChild(document.createTextNode(e)),s.appendChild(i),s}showMessageNode(t){t.classList.add("er-toast__message--hidden"),requestAnimationFrame(()=>{this.toastNode.appendChild(t),requestAnimationFrame(()=>{t.classList.remove("er-toast__message--hidden")})}),this.scheduleHiding(t)}hideMessageNode(t){t.classList.add("er-toast__message--hidden"),setTimeout(()=>{this.toastNode.contains(t)&&this.toastNode.removeChild(t)},this.getTransitionDuration(t))}showSuccess({title:t="",text:e=""}={}){let s=this.getMessageNode({title:t,text:e});s.classList.add("er-toast__message--success"),this.showMessageNode(s)}showError({title:t="",text:e=""}={}){let s=this.getMessageNode({title:t,text:e});s.classList.add("er-toast__message--error"),this.showMessageNode(s)}}t.Toast=new e}(window.EComRise||{});